package com.warmlight.voicepacket.network.manager;


import com.google.gson.reflect.TypeToken;
import com.warmlight.voicepacket.bean.cdetails.CDetailsBean;
import com.warmlight.voicepacket.bean.comm.CommBean;
import com.warmlight.voicepacket.network.CommonHelper;
import com.warmlight.voicepacket.network.api.CommService;
import com.warmlight.voicepacket.network.base.BaseResponse;
import com.warmlight.voicepacket.network.base.BaseSubscriber;
import com.warmlight.voicepacket.network.base.NetworkCallback;
import com.warmlight.voicepacket.network.base.NetworkCallbackLike;

import java.util.Map;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by weiweijinpeng on 2018/8/13.
 */

public class CommRequestManager {

    private static CommRequestManager instance=null;

    /**
     * 请求接口
     */
    private CommService commService;

    public static CommRequestManager getInstance(){
        if (instance==null){
            synchronized (CommRequestManager.class){
                instance=new CommRequestManager();
            }
        }
        return instance;
    }

    private CommRequestManager(){
        commService = CommonHelper.createApi(CommService.class);
    }

    /**
     * 推荐数据
     * @param
     * @param map*/
    public void getRecommList(Map<String,Object> map, NetworkCallback<CommBean> callback){
        commService.setRecomm(map)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.newThread())
                .subscribe(new BaseSubscriber<>(callback,new TypeToken<BaseResponse<CommBean>>(){}));
    }

    /**
     * 点赞数据
     * @param
     * @param map*/
    public void getLike(Map<String,Object> map, NetworkCallbackLike<CommBean> callback){
        commService.setLike(map)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.newThread())
                .subscribe(new BaseSubscriber<>(callback,new TypeToken<BaseResponse<CommBean>>(){}));
    }

    /**
     * 社区详情数据
     * @param
     * @param map*/
    public void getVDetails(Map<String,Object> map, NetworkCallback<CDetailsBean> callback){
        commService.setVDetails(map)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.newThread())
                .subscribe(new BaseSubscriber<>(callback,new TypeToken<BaseResponse<CDetailsBean>>(){}));
    }

    /**
     * 话题详情数据
     * @param
     * @param map*/
    public void getTopicList(Map<String,Object> map, NetworkCallback<CommBean> callback){
        commService.setTopic(map)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.newThread())
                .subscribe(new BaseSubscriber<>(callback,new TypeToken<BaseResponse<CommBean>>(){}));
    }

}
